vline <- function(x = 0, color = "red") {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color)
)
}
Rectangles <- list()
for (i in seq_along(LocalExons.GR)) {
Rectangle<-list()
Rectangle[["x0"]] <- start(LocalExons.GR)[i]
Rectangle[["x1"]] <- end(LocalExons.GR)[i]
Rectangle[["y0"]] <- as.numeric(LocalExons.GR$Height[i])
Rectangle[["y1"]] <- as.numeric(LocalExons.GR$Height[i])+0.75
Rectangle[["type"]] <- "rect"
Rectangle[["fillcolor"]] <- "purple"
Rectangle[["line"]] = list(color = "blue")
Rectangle[["opacity"]] = 0.3
Rectangle[["xref"]] = "x"
Rectangle[["yref"]] = "y"
Rectangles <- c(Rectangles, list(Rectangle))
}
transcripts <- list()
for (i in 1:dim(LocalTranscripts)[1]) {
line<-list()
line[["type"]]="line"
line[["line"]] = list(color = "#0000FF12")
line[["xref"]] = "x"
line[["yref"]] = "y"
line[["x0"]] <- LocalTranscripts$Tx_start[i]
line[["x1"]] <- LocalTranscripts$Tx_end[i]
line[c("y0", "y1")] <- LocalTranscripts$Height[i]+0.25
transcripts <- c(transcripts, list(line))
}
Rectangles <- c(transcripts,Rectangles, list(vline(14482180)),list(vline(14513695)))
fig1<-plot_ly(data=LocalBG,y = ~`Log R Ratio`,x=~Position, type =
"box",marker = list(width=50))
fig1<-add_trace(fig1,data=LocalSample,
type = 'scatter',mode = 'markers',
x = ~Position,
y = ~`Log R Ratio`,
text=~`SNP Name`,
hovertemplate = paste('SNP name: %{text}<br>Log R Ratio: %{y}<extra></extra>'))
fig1 <- layout(fig1,shapes=c(list(vline(14482180)),list(vline(14513695))),yaxis =list(range=c(-2,2),constrain="domain",fixedrange=TRUE))
fig2<-plot_ly()
fig2<-layout(fig2,
shapes=Rectangles,
xaxis =list(range=c(14482180-(14513695-14482180)*0.33,14513695+(14513695-14482180)*0.33),constrain="domain",showgrid = FALSE),
yaxis =list(range=c(2,30),constrain="domain",fixedrange=TRUE,
showgrid = FALSE))
fig2<-add_trace(fig2,
type="scatter",
mode="markers",
y = as.numeric(LocalExons.GR$Height)+0.5,
x = as.numeric(LocalExons.GR$MIDDLE),
text = paste0(
LocalExons.GR$gene_name,"\n",
LocalExons.GR$transcript_id,"\n",
LocalExons.GR$exon_id),
hovertemplate = paste('%{text}<extra></extra>'),
marker = list(
color = '00FFFFFF',
size = 0.1,
line = list(
color = '00FFFFFF',
width = 0.1
)))
figB <- plot_ly(data = LocalSample, x = ~Position, y = ~`B Allele Freq`,text=~`SNP Name`,hovertemplate = paste('SNP: %{text}<br>BAF: %{y}<extra></extra>'))
figB<-layout(figB,
xaxis =list(range=c(14482180-(14513695-14482180)*0.33,14513695+(14513695-14482180)*0.33),constrain="domain"),
yaxis =list(range=c(-0.1,1.1),constrain="domain",fixedrange=TRUE),
shapes=list(vline(14482180),vline(14513695)))
fig <- subplot(fig1, fig2,figB,nrows = 3,shareX = TRUE)
fig<-layout(fig,
hovermode="x unified",
showlegend = FALSE,
xaxis = list(hoverformat = 'Position: %{x,d}<extra></extra>'),
hoverlabel='Position: %{x,d}<extra></extra>')
fig